forumdat<-read.csv("C:/Users/cdanm/Dropbox/Current_Projects/Dissertation Article One/Data Analysis/20150730_Diss1_Field_Individual_Replication.csv")

#Drop Experts

nexpdat<-forumdat[which(forumdat$SeatActual!=1),]

#generate means and conf intervals for reactions to expert info. This is to create Figure 2 in paper

meanthought1<-4-mean(nexpdat$meanexpthought[which(nexpdat$majexp==0)],na.rm=T)
errorthought1<-qnorm(.95)*sd(nexpdat$meanexpthought[which(nexpdat$majexp==0)],na.rm=T)/sqrt(length(nexpdat$meanexpthought[which(nexpdat$majexp==0)]))
confthought1<-c(meanthought1-errorthought1,meanthought1+errorthought1)

meanthought2<-4-mean(nexpdat$meanexpthought[which(nexpdat$majexp==1)],na.rm=T)
errorthought2<-qnorm(.95)*sd(nexpdat$meanexpthought[which(nexpdat$majexp==1)],na.rm=T)/sqrt(length(nexpdat$meanexpthought[which(nexpdat$majexp==1)]))
confthought2<-c(meanthought2-errorthought2,meanthought2+errorthought2)

meanimp1<-4-mean(nexpdat$meanexpimp[which(nexpdat$majexp==0)],na.rm=T)
errorimp1<-qnorm(.95)*sd(nexpdat$meanexpimp[which(nexpdat$majexp==0)],na.rm=T)/sqrt(length(nexpdat$meanexpimp[which(nexpdat$majexp==0)]))
confimp1<-c(meanimp1-errorimp1,meanimp1+errorimp1)

meanimp2<-4-mean(nexpdat$meanexpimp[which(nexpdat$majexp==1)],na.rm=T)
errorimp2<-qnorm(.95)*sd(nexpdat$meanexpimp[which(nexpdat$majexp==1)],na.rm=T)/sqrt(length(nexpdat$meanexpimp[which(nexpdat$majexp==1)]))
confimp2<-c(meanimp2-errorimp2,meanimp2+errorimp2)

meanagree1<-5-mean(nexpdat$meanexpagree[which(nexpdat$majexp==0)],na.rm=T)
erroragree1<-qnorm(.95)*sd(nexpdat$meanexpagree[which(nexpdat$majexp==0)],na.rm=T)/sqrt(length(nexpdat$meanexpagree[which(nexpdat$majexp==0)]))
confagree1<-c(meanagree1-erroragree1,meanagree1+erroragree1)

meanagree2<-5-mean(nexpdat$meanexpagree[which(nexpdat$majexp==1)],na.rm=T)
erroragree2<-qnorm(.95)*sd(nexpdat$meanexpagree[which(nexpdat$majexp==1)],na.rm=T)/sqrt(length(nexpdat$meanexpagree[which(nexpdat$majexp==1)]))
confagree2<-c(meanagree2-erroragree2,meanagree2+erroragree2)

#Generates means and confidence intervals for reactions to non-expert information

meanthought3<-4-mean(nexpdat$meannonthought[which(nexpdat$majexp==0)],na.rm=T)
errorthought3<-qnorm(.95)*sd(nexpdat$meannonthought[which(nexpdat$majexp==0)],na.rm=T)/sqrt(length(nexpdat$meannonthought[which(nexpdat$majexp==0)]))
confthought3<-c(meanthought3-errorthought3,meanthought3+errorthought3)

meanthought4<-4-mean(nexpdat$meannonthought[which(nexpdat$majexp==1)],na.rm=T)
errorthought4<-qnorm(.95)*sd(nexpdat$meannonthought[which(nexpdat$majexp==1)],na.rm=T)/sqrt(length(nexpdat$meannonthought[which(nexpdat$majexp==1)]))
confthought4<-c(meanthought4-errorthought4,meanthought4+errorthought4)

meanimp3<-4-mean(nexpdat$meannonimp[which(nexpdat$majexp==0)],na.rm=T)
errorimp3<-qnorm(.95)*sd(nexpdat$meannonimp[which(nexpdat$majexp==0)],na.rm=T)/sqrt(length(nexpdat$meannonimp[which(nexpdat$majexp==0)]))
confimp3<-c(meanimp3-errorimp3,meanimp3+errorimp3)

meanimp4<-4-mean(nexpdat$meannonimp[which(nexpdat$majexp==1)],na.rm=T)
errorimp4<-qnorm(.95)*sd(nexpdat$meannonimp[which(nexpdat$majexp==1)],na.rm=T)/sqrt(length(nexpdat$meannonimp[which(nexpdat$majexp==1)]))
confimp4<-c(meanimp4-errorimp4,meanimp4+errorimp4)

meanagree3<-5-mean(nexpdat$meannonagree[which(nexpdat$majexp==0)],na.rm=T)
erroragree3<-qnorm(.95)*sd(nexpdat$meannonagree[which(nexpdat$majexp==0)],na.rm=T)/sqrt(length(nexpdat$meannonagree[which(nexpdat$majexp==0)]))
confagree3<-c(meanagree3-erroragree3,meanagree3+erroragree3)

meanagree4<-5-mean(nexpdat$meannonagree[which(nexpdat$majexp==1)],na.rm=T)
erroragree4<-qnorm(.95)*sd(nexpdat$meannonagree[which(nexpdat$majexp==1)],na.rm=T)/sqrt(length(nexpdat$meannonagree[which(nexpdat$majexp==1)]))
confagree4<-c(meanagree4-erroragree4,meanagree4+erroragree4)

##Create Figure 2

library(gplots)

plotmatrix1<-matrix(c(meanthought1,meanthought2,meanimp1,meanimp2,meanagree1,meanagree2),nrow=2,ncol=3,byrow=F)
cilmatrix1<-matrix(c(confthought1[1],confthought2[1],confimp1[1],confimp2[1],confagree1[1],confagree2[1]),nrow=2,ncol=3,byrow=F)
ciumatrix1<-matrix(c(confthought1[2],confthought2[2],confimp1[2],confimp2[2],confagree1[2],confagree2[2]),nrow=2,ncol=3,byrow=F)

barplot2(plotmatrix1,beside=T,plot.ci=T,ci.l=cilmatrix1,ci.u=ciumatrix1,main="Reactions to Expert Arguments",ylab = "Less --------------------- More",names.arg=c("Thought About","Consider Important","Agree with"),ylim=c(0,3),col=c(gray(.25),gray(.75)))
legend(x=1,y=3,legend=c("Expert in Minority (N=23)","Expert in Majority (N=33)"),fill=c(gray(.25),gray(.75)))

#T-tests reported in 3rd paragraph of results section

t.test(nexpdat$meanexpthought[which(nexpdat$majexp==0)], nexpdat$meanexpthought[which(nexpdat$majexp==1)],na.rm=T, alternative="greater")
t.test(nexpdat$meanexpimp[which(nexpdat$majexp==0)], nexpdat$meanexpimp[which(nexpdat$majexp==1)],na.rm=T, alternative="greater")
t.test(nexpdat$meanexpagree[which(nexpdat$majexp==0)], nexpdat$meanexpagree[which(nexpdat$majexp==1)],na.rm=T, alternative="greater")

#Mean and SD reported in 3rd paragraph of results section

mean(nexpdat$meanexpagree[which(nexpdat$majexp==0)], na.rm=T)-mean(nexpdat$meanexpagree[which(nexpdat$majexp==1)], na.rm=T)
.5428571/sd(nexpdat$meanexpagree, na.rm=T)

##Subset dataset to only members of the majority

nexpdatmaj<-forumdat[which(forumdat$SeatActual!=1),]


nexpdatmaj$prosports<-ifelse(nexpdatmaj$Sports.Teams>4,1,0)

nexpdatmaj<-nexpdatmaj[which(nexpdatmaj$prosports == nexpdatmaj$prosportsmaj),]

#generate means and conf intervals for reactions to expert info

meanthought1<-4-mean(nexpdatmaj$meanexpthought[which(nexpdatmaj$majexp==0)],na.rm=T)
errorthought1<-qnorm(.95)*sd(nexpdatmaj$meanexpthought[which(nexpdatmaj$majexp==0)],na.rm=T)/sqrt(length(nexpdatmaj$meanexpthought[which(nexpdatmaj$majexp==0)]))
confthought1<-c(meanthought1-errorthought1,meanthought1+errorthought1)

meanthought2<-4-mean(nexpdatmaj$meanexpthought[which(nexpdatmaj$majexp==1)],na.rm=T)
errorthought2<-qnorm(.95)*sd(nexpdatmaj$meanexpthought[which(nexpdatmaj$majexp==1)],na.rm=T)/sqrt(length(nexpdatmaj$meanexpthought[which(nexpdatmaj$majexp==1)]))
confthought2<-c(meanthought2-errorthought2,meanthought2+errorthought2)

meanimp1<-4-mean(nexpdatmaj$meanexpimp[which(nexpdatmaj$majexp==0)],na.rm=T)
errorimp1<-qnorm(.95)*sd(nexpdatmaj$meanexpimp[which(nexpdatmaj$majexp==0)],na.rm=T)/sqrt(length(nexpdatmaj$meanexpimp[which(nexpdatmaj$majexp==0)]))
confimp1<-c(meanimp1-errorimp1,meanimp1+errorimp1)

meanimp2<-4-mean(nexpdatmaj$meanexpimp[which(nexpdatmaj$majexp==1)],na.rm=T)
errorimp2<-qnorm(.95)*sd(nexpdatmaj$meanexpimp[which(nexpdatmaj$majexp==1)],na.rm=T)/sqrt(length(nexpdatmaj$meanexpimp[which(nexpdatmaj$majexp==1)]))
confimp2<-c(meanimp2-errorimp2,meanimp2+errorimp2)

meanagree1<-5-mean(nexpdatmaj$meanexpagree[which(nexpdatmaj$majexp==0)],na.rm=T)
erroragree1<-qnorm(.95)*sd(nexpdatmaj$meanexpagree[which(nexpdatmaj$majexp==0)],na.rm=T)/sqrt(length(nexpdatmaj$meanexpagree[which(nexpdatmaj$majexp==0)]))
confagree1<-c(meanagree1-erroragree1,meanagree1+erroragree1)

meanagree2<-5-mean(nexpdatmaj$meanexpagree[which(nexpdatmaj$majexp==1)],na.rm=T)
erroragree2<-qnorm(.95)*sd(nexpdatmaj$meanexpagree[which(nexpdatmaj$majexp==1)],na.rm=T)/sqrt(length(nexpdatmaj$meanexpagree[which(nexpdatmaj$majexp==1)]))
confagree2<-c(meanagree2-erroragree2,meanagree2+erroragree2)

#Creates Figure 3

library(gplots)

plotmatrix1<-matrix(c(meanthought1,meanthought2,meanimp1,meanimp2,meanagree1,meanagree2),nrow=2,ncol=3,byrow=F)
cilmatrix1<-matrix(c(confthought1[1],confthought2[1],confimp1[1],confimp2[1],confagree1[1],confagree2[1]),nrow=2,ncol=3,byrow=F)
ciumatrix1<-matrix(c(confthought1[2],confthought2[2],confimp1[2],confimp2[2],confagree1[2],confagree2[2]),nrow=2,ncol=3,byrow=F)

barplot2(plotmatrix1,beside=T,plot.ci=T,ci.l=cilmatrix1,ci.u=ciumatrix1,main="Reactions to Expert Arguments, Members of Minority Only",ylab = "Less --------------------- More",names.arg=c("Thought About","Consider Important","Agree with"),ylim=c(0,3),col=c(gray(.25),gray(.75)))
legend(x=2,y=3,legend=c("Expert in Minority (N=8)","Expert in Majority (N=13)"),fill=c(gray(.25),gray(.75)))

#Conduct t-tests reported in 4th paragraph of results section

t.test(nexpdatmaj$meanexpthought[which(nexpdatmaj$majexp==0)], nexpdatmaj$meanexpthought[which(nexpdatmaj$majexp==1)],na.rm=T, alternative="greater")
t.test(nexpdatmaj$meanexpimp[which(nexpdatmaj$majexp==0)], nexpdatmaj$meanexpimp[which(nexpdatmaj$majexp==1)],na.rm=T, alternative="greater")
t.test(nexpdatmaj$meanexpagree[which(nexpdatmaj$majexp==0)], nexpdatmaj$meanexpagree[which(nexpdatmaj$majexp==1)],na.rm=T, alternative="greater")



##Subset dataset to only members of the minority

nexpdatmin<-forumdat[which(forumdat$SeatActual!=1),]

nexpdatmin$prosports<-ifelse(nexpdatmin$Sports.Teams>4,1,0)

nexpdatmin<-nexpdatmin[which(nexpdatmin$prosports != nexpdatmin$prosportsmaj),]

#generate means and conf intervals for reactions to expert info

meanthought1<-4-mean(nexpdatmin$meanexpthought[which(nexpdatmin$majexp==0)],na.rm=T)
errorthought1<-qnorm(.95)*sd(nexpdatmin$meanexpthought[which(nexpdatmin$majexp==0)],na.rm=T)/sqrt(length(nexpdatmin$meanexpthought[which(nexpdatmin$majexp==0)]))
confthought1<-c(meanthought1-errorthought1,meanthought1+errorthought1)

meanthought2<-4-mean(nexpdatmin$meanexpthought[which(nexpdatmin$majexp==1)],na.rm=T)
errorthought2<-qnorm(.95)*sd(nexpdatmin$meanexpthought[which(nexpdatmin$majexp==1)],na.rm=T)/sqrt(length(nexpdatmin$meanexpthought[which(nexpdatmin$majexp==1)]))
confthought2<-c(meanthought2-errorthought2,meanthought2+errorthought2)

meanimp1<-4-mean(nexpdatmin$meanexpimp[which(nexpdatmin$majexp==0)],na.rm=T)
errorimp1<-qnorm(.95)*sd(nexpdatmin$meanexpimp[which(nexpdatmin$majexp==0)],na.rm=T)/sqrt(length(nexpdatmin$meanexpimp[which(nexpdatmin$majexp==0)]))
confimp1<-c(meanimp1-errorimp1,meanimp1+errorimp1)

meanimp2<-4-mean(nexpdatmin$meanexpimp[which(nexpdatmin$majexp==1)],na.rm=T)
errorimp2<-qnorm(.95)*sd(nexpdatmin$meanexpimp[which(nexpdatmin$majexp==1)],na.rm=T)/sqrt(length(nexpdatmin$meanexpimp[which(nexpdatmin$majexp==1)]))
confimp2<-c(meanimp2-errorimp2,meanimp2+errorimp2)

meanagree1<-5-mean(nexpdatmin$meanexpagree[which(nexpdatmin$majexp==0)],na.rm=T)
erroragree1<-qnorm(.95)*sd(nexpdatmin$meanexpagree[which(nexpdatmin$majexp==0)],na.rm=T)/sqrt(length(nexpdatmin$meanexpagree[which(nexpdatmin$majexp==0)]))
confagree1<-c(meanagree1-erroragree1,meanagree1+erroragree1)

meanagree2<-5-mean(nexpdatmin$meanexpagree[which(nexpdatmin$majexp==1)],na.rm=T)
erroragree2<-qnorm(.95)*sd(nexpdatmin$meanexpagree[which(nexpdatmin$majexp==1)],na.rm=T)/sqrt(length(nexpdatmin$meanexpagree[which(nexpdatmin$majexp==1)]))
confagree2<-c(meanagree2-erroragree2,meanagree2+erroragree2)

#Creates Figure 4

library(gplots)

plotmatrix1<-matrix(c(meanthought1,meanthought2,meanimp1,meanimp2,meanagree1,meanagree2),nrow=2,ncol=3,byrow=F)
cilmatrix1<-matrix(c(confthought1[1],confthought2[1],confimp1[1],confimp2[1],confagree1[1],confagree2[1]),nrow=2,ncol=3,byrow=F)
ciumatrix1<-matrix(c(confthought1[2],confthought2[2],confimp1[2],confimp2[2],confagree1[2],confagree2[2]),nrow=2,ncol=3,byrow=F)

barplot2(plotmatrix1,beside=T,plot.ci=T,ci.l=cilmatrix1,ci.u=ciumatrix1,main="Reactions to Expert Arguments, Members of Minority Only",ylab = "Less --------------------- More",names.arg=c("Thought About","Consider Important","Agree with"),ylim=c(0,3),col=c(gray(.25),gray(.75)))
legend(x=2,y=3,legend=c("Expert in Minority (N=8)","Expert in Majority (N=13)"),fill=c(gray(.25),gray(.75)))

#Conduct t-tests reported in 4th paragraph of results section

t.test(nexpdatmin$meanexpthought[which(nexpdatmin$majexp==0)], nexpdatmin$meanexpthought[which(nexpdatmin$majexp==1)],na.rm=T, alternative="greater")
t.test(nexpdatmin$meanexpimp[which(nexpdatmin$majexp==0)], nexpdatmin$meanexpimp[which(nexpdatmin$majexp==1)],na.rm=T, alternative="greater")
t.test(nexpdatmin$meanexpagree[which(nexpdatmin$majexp==0)], nexpdatmin$meanexpagree[which(nexpdatmin$majexp==1)],na.rm=T, alternative="greater")


##Running cluster standard error models in Table 6
##Requires packages sandwich and 

cl   <- function(dat,fm, cluster){

           require(sandwich, quietly = TRUE)

           require(lmtest, quietly = TRUE)

           M <- length(unique(cluster))

           N <- length(cluster)

           K <- fm$rank

           dfc <- (M/(M-1))*((N-1)/(N-K))

           uj  <- apply(estfun(fm),2, function(x) tapply(x, cluster, sum));

           vcovCL <- dfc*sandwich(fm, meat=crossprod(uj)/N)

           coeftest(fm, vcovCL) }

#Note that I reversed the coding of the dependent variables so that higher numbers = more

model<-lm(meanexpagree ~ majexp, data=nexpdat)
cl(nexpdat, model, nexpdat$TableActual[which(is.na(nexpdat$meanexpagree)==F)])

model<-lm(meanexpagree ~ majexp, data=nexpdatmaj)
cl(nexpdatmaj, model, nexpdatmaj$TableActual[which(is.na(nexpdatmaj$meanexpagree)==F)])

model<-lm(meanexpagree ~ majexp, data=nexpdatmin)
cl(nexpdatmin, model, nexpdatmin$TableActual[which(is.na(nexpdatmin$meanexpagree)==F)])


model<-lm(meanexpimp ~ majexp, data=nexpdat)
cl(nexpdat, model, nexpdat$TableActual[which(is.na(nexpdat$meanexpimp)==F)])

model<-lm(meanexpimp ~ majexp, data=nexpdatmaj)
cl(nexpdatmaj, model, nexpdatmaj$TableActual[which(is.na(nexpdatmaj$meanexpimp)==F)])

model<-lm(meanexpimp ~ majexp, data=nexpdatmin)
cl(nexpdatmin, model, nexpdatmin$TableActual[which(is.na(nexpdatmin$meanexpimp)==F)])

model<-lm(meanexpthought ~ majexp, data=nexpdat)
cl(nexpdat, model, nexpdat$TableActual[which(is.na(nexpdat$meanexpthought)==F)])

model<-lm(meanexpthought ~ majexp, data=nexpdatmaj)
cl(nexpdatmaj, model, nexpdatmaj$TableActual[which(is.na(nexpdatmaj$meanexpthought)==F)])

model<-lm(meanexpthought ~ majexp, data=nexpdatmin)
cl(nexpdatmin, model, nexpdatmin$TableActual[which(is.na(nexpdatmin$meanexpthought)==F)])

##Now onto the appendecies

#Generate Figure 1 in the appendix

meanthought1<-4-mean(nexpdat$expfavthought[which(nexpdat$majexp==0)],na.rm=T)
errorthought1<-qnorm(.95)*sd(nexpdat$expfavthought[which(nexpdat$majexp==0)],na.rm=T)/sqrt(length(nexpdat$expfavthought[which(nexpdat$majexp==0)]))
confthought1<-c(meanthought1-errorthought1,meanthought1+errorthought1)

meanthought2<-4-mean(nexpdat$expfavthought[which(nexpdat$majexp==1)],na.rm=T)
errorthought2<-qnorm(.95)*sd(nexpdat$expfavthought[which(nexpdat$majexp==1)],na.rm=T)/sqrt(length(nexpdat$expfavthought[which(nexpdat$majexp==1)]))
confthought2<-c(meanthought2-errorthought2,meanthought2+errorthought2)

meanimp1<-4-mean(nexpdat$expfavimp[which(nexpdat$majexp==0)],na.rm=T)
errorimp1<-qnorm(.95)*sd(nexpdat$expfavimp[which(nexpdat$majexp==0)],na.rm=T)/sqrt(length(nexpdat$expfavimp[which(nexpdat$majexp==0)]))
confimp1<-c(meanimp1-errorimp1,meanimp1+errorimp1)

meanimp2<-4-mean(nexpdat$expfavimp[which(nexpdat$majexp==1)],na.rm=T)
errorimp2<-qnorm(.95)*sd(nexpdat$expfavimp[which(nexpdat$majexp==1)],na.rm=T)/sqrt(length(nexpdat$expfavimp[which(nexpdat$majexp==1)]))
confimp2<-c(meanimp2-errorimp2,meanimp2+errorimp2)

meanagree1<-5-mean(nexpdat$expfavagree[which(nexpdat$majexp==0)],na.rm=T)
erroragree1<-qnorm(.95)*sd(nexpdat$expfavagree[which(nexpdat$majexp==0)],na.rm=T)/sqrt(length(nexpdat$expfavagree[which(nexpdat$majexp==0)]))
confagree1<-c(meanagree1-erroragree1,meanagree1+erroragree1)

meanagree2<-5-mean(nexpdat$expfavagree[which(nexpdat$majexp==1)],na.rm=T)
erroragree2<-qnorm(.95)*sd(nexpdat$expfavagree[which(nexpdat$majexp==1)],na.rm=T)/sqrt(length(nexpdat$expfavagree[which(nexpdat$majexp==1)]))
confagree2<-c(meanagree2-erroragree2,meanagree2+erroragree2)

plotmatrix1<-matrix(c(meanthought1,meanthought2,meanimp1,meanimp2,meanagree1,meanagree2),nrow=2,ncol=3,byrow=F)
cilmatrix1<-matrix(c(confthought1[1],confthought2[1],confimp1[1],confimp2[1],confagree1[1],confagree2[1]),nrow=2,ncol=3,byrow=F)
ciumatrix1<-matrix(c(confthought1[2],confthought2[2],confimp1[2],confimp2[2],confagree1[2],confagree2[2]),nrow=2,ncol=3,byrow=F)

barplot2(plotmatrix1,beside=T,plot.ci=T,ci.l=cilmatrix1,ci.u=ciumatrix1,main="Reactions to Expert-Favored Argument",ylab = "Less --------------------- More",names.arg=c("Thought About","Consider Important","Agree with"),ylim=c(0,3),col=c(gray(.25),gray(.75)))
legend(x=1,y=3,legend=c("Expert in Minority (N=23)","Expert in Majority (N=33)"),fill=c(gray(.25),gray(.75)))

t.test(nexpdat$expfavthought[which(nexpdat$majexp==0)], nexpdat$expfavthought[which(nexpdat$majexp==1)],na.rm=T, alternative="greater")
t.test(nexpdat$expfavimp[which(nexpdat$majexp==0)], nexpdat$expfavimp[which(nexpdat$majexp==1)],na.rm=T, alternative="greater")
t.test(nexpdat$expfavagree[which(nexpdat$majexp==0)], nexpdat$expfavagree[which(nexpdat$majexp==1)],na.rm=T, alternative="greater")


#Generate Figure 2 in the appendix

meanthought1<-4-mean(nexpdat$expoppthought[which(nexpdat$majexp==0)],na.rm=T)
errorthought1<-qnorm(.95)*sd(nexpdat$expoppthought[which(nexpdat$majexp==0)],na.rm=T)/sqrt(length(nexpdat$expoppthought[which(nexpdat$majexp==0)]))
confthought1<-c(meanthought1-errorthought1,meanthought1+errorthought1)

meanthought2<-4-mean(nexpdat$expoppthought[which(nexpdat$majexp==1)],na.rm=T)
errorthought2<-qnorm(.95)*sd(nexpdat$expoppthought[which(nexpdat$majexp==1)],na.rm=T)/sqrt(length(nexpdat$expoppthought[which(nexpdat$majexp==1)]))
confthought2<-c(meanthought2-errorthought2,meanthought2+errorthought2)

meanimp1<-4-mean(nexpdat$expoppimp[which(nexpdat$majexp==0)],na.rm=T)
errorimp1<-qnorm(.95)*sd(nexpdat$expoppimp[which(nexpdat$majexp==0)],na.rm=T)/sqrt(length(nexpdat$expoppimp[which(nexpdat$majexp==0)]))
confimp1<-c(meanimp1-errorimp1,meanimp1+errorimp1)

meanimp2<-4-mean(nexpdat$expoppimp[which(nexpdat$majexp==1)],na.rm=T)
errorimp2<-qnorm(.95)*sd(nexpdat$expoppimp[which(nexpdat$majexp==1)],na.rm=T)/sqrt(length(nexpdat$expoppimp[which(nexpdat$majexp==1)]))
confimp2<-c(meanimp2-errorimp2,meanimp2+errorimp2)

meanagree1<-5-mean(nexpdat$expoppagree[which(nexpdat$majexp==0)],na.rm=T)
erroragree1<-qnorm(.95)*sd(nexpdat$expoppagree[which(nexpdat$majexp==0)],na.rm=T)/sqrt(length(nexpdat$expoppagree[which(nexpdat$majexp==0)]))
confagree1<-c(meanagree1-erroragree1,meanagree1+erroragree1)

meanagree2<-5-mean(nexpdat$expoppagree[which(nexpdat$majexp==1)],na.rm=T)
erroragree2<-qnorm(.95)*sd(nexpdat$expoppagree[which(nexpdat$majexp==1)],na.rm=T)/sqrt(length(nexpdat$expoppagree[which(nexpdat$majexp==1)]))
confagree2<-c(meanagree2-erroragree2,meanagree2+erroragree2)

plotmatrix1<-matrix(c(meanthought1,meanthought2,meanimp1,meanimp2,meanagree1,meanagree2),nrow=2,ncol=3,byrow=F)
cilmatrix1<-matrix(c(confthought1[1],confthought2[1],confimp1[1],confimp2[1],confagree1[1],confagree2[1]),nrow=2,ncol=3,byrow=F)
ciumatrix1<-matrix(c(confthought1[2],confthought2[2],confimp1[2],confimp2[2],confagree1[2],confagree2[2]),nrow=2,ncol=3,byrow=F)

barplot2(plotmatrix1,beside=T,plot.ci=T,ci.l=cilmatrix1,ci.u=ciumatrix1,main="Reactions to Expert-Opposed Argument",ylab = "Less --------------------- More",names.arg=c("Thought About","Consider Important","Agree with"),ylim=c(0,3),col=c(gray(.25),gray(.75)))
legend(x=1,y=3,legend=c("Expert in Minority (N=23)","Expert in Majority (N=33)"),fill=c(gray(.25),gray(.75)))

t.test(nexpdat$expoppthought[which(nexpdat$majexp==0)], nexpdat$expoppthought[which(nexpdat$majexp==1)],na.rm=T, alternative="greater")
t.test(nexpdat$expoppimp[which(nexpdat$majexp==0)], nexpdat$expoppimp[which(nexpdat$majexp==1)],na.rm=T, alternative="greater")
t.test(nexpdat$expoppagree[which(nexpdat$majexp==0)], nexpdat$expoppagree[which(nexpdat$majexp==1)],na.rm=T, alternative="greater")

##Generate Figure 3 in Appendix, Hist of pre-discussion rankings

hist(forumdat$Sports.Teams)

##Generate Figures 4 and 5 in Appendix, re-analysis using a 5-6 cutpoint

meanthought1<-4-mean(nexpdat$meanexpthought[which(nexpdat$majexp6==0)],na.rm=T)
errorthought1<-qnorm(.95)*sd(nexpdat$meanexpthought[which(nexpdat$majexp6==0)],na.rm=T)/sqrt(length(nexpdat$meanexpthought[which(nexpdat$majexp6==0)]))
confthought1<-c(meanthought1-errorthought1,meanthought1+errorthought1)

meanthought2<-4-mean(nexpdat$meanexpthought[which(nexpdat$majexp6==1)],na.rm=T)
errorthought2<-qnorm(.95)*sd(nexpdat$meanexpthought[which(nexpdat$majexp6==1)],na.rm=T)/sqrt(length(nexpdat$meanexpthought[which(nexpdat$majexp6==1)]))
confthought2<-c(meanthought2-errorthought2,meanthought2+errorthought2)

meanimp1<-4-mean(nexpdat$meanexpimp[which(nexpdat$majexp6==0)],na.rm=T)
errorimp1<-qnorm(.95)*sd(nexpdat$meanexpimp[which(nexpdat$majexp6==0)],na.rm=T)/sqrt(length(nexpdat$meanexpimp[which(nexpdat$majexp6==0)]))
confimp1<-c(meanimp1-errorimp1,meanimp1+errorimp1)

meanimp2<-4-mean(nexpdat$meanexpimp[which(nexpdat$majexp6==1)],na.rm=T)
errorimp2<-qnorm(.95)*sd(nexpdat$meanexpimp[which(nexpdat$majexp6==1)],na.rm=T)/sqrt(length(nexpdat$meanexpimp[which(nexpdat$majexp6==1)]))
confimp2<-c(meanimp2-errorimp2,meanimp2+errorimp2)

meanagree1<-5-mean(nexpdat$meanexpagree[which(nexpdat$majexp6==0)],na.rm=T)
erroragree1<-qnorm(.95)*sd(nexpdat$meanexpagree[which(nexpdat$majexp6==0)],na.rm=T)/sqrt(length(nexpdat$meanexpagree[which(nexpdat$majexp6==0)]))
confagree1<-c(meanagree1-erroragree1,meanagree1+erroragree1)

meanagree2<-5-mean(nexpdat$meanexpagree[which(nexpdat$majexp6==1)],na.rm=T)
erroragree2<-qnorm(.95)*sd(nexpdat$meanexpagree[which(nexpdat$majexp6==1)],na.rm=T)/sqrt(length(nexpdat$meanexpagree[which(nexpdat$majexp6==1)]))
confagree2<-c(meanagree2-erroragree2,meanagree2+erroragree2)

#Generates means and confidence intervals for reactions to non-expert information

meanthought3<-4-mean(nexpdat$meannonthought[which(nexpdat$majexp6==0)],na.rm=T)
errorthought3<-qnorm(.95)*sd(nexpdat$meannonthought[which(nexpdat$majexp6==0)],na.rm=T)/sqrt(length(nexpdat$meannonthought[which(nexpdat$majexp6==0)]))
confthought3<-c(meanthought3-errorthought3,meanthought3+errorthought3)

meanthought4<-4-mean(nexpdat$meannonthought[which(nexpdat$majexp6==1)],na.rm=T)
errorthought4<-qnorm(.95)*sd(nexpdat$meannonthought[which(nexpdat$majexp6==1)],na.rm=T)/sqrt(length(nexpdat$meannonthought[which(nexpdat$majexp6==1)]))
confthought4<-c(meanthought4-errorthought4,meanthought4+errorthought4)

meanimp3<-4-mean(nexpdat$meannonimp[which(nexpdat$majexp6==0)],na.rm=T)
errorimp3<-qnorm(.95)*sd(nexpdat$meannonimp[which(nexpdat$majexp6==0)],na.rm=T)/sqrt(length(nexpdat$meannonimp[which(nexpdat$majexp6==0)]))
confimp3<-c(meanimp3-errorimp3,meanimp3+errorimp3)

meanimp4<-4-mean(nexpdat$meannonimp[which(nexpdat$majexp6==1)],na.rm=T)
errorimp4<-qnorm(.95)*sd(nexpdat$meannonimp[which(nexpdat$majexp6==1)],na.rm=T)/sqrt(length(nexpdat$meannonimp[which(nexpdat$majexp6==1)]))
confimp4<-c(meanimp4-errorimp4,meanimp4+errorimp4)

meanagree3<-5-mean(nexpdat$meannonagree[which(nexpdat$majexp6==0)],na.rm=T)
erroragree3<-qnorm(.95)*sd(nexpdat$meannonagree[which(nexpdat$majexp6==0)],na.rm=T)/sqrt(length(nexpdat$meannonagree[which(nexpdat$majexp6==0)]))
confagree3<-c(meanagree3-erroragree3,meanagree3+erroragree3)

meanagree4<-5-mean(nexpdat$meannonagree[which(nexpdat$majexp6==1)],na.rm=T)
erroragree4<-qnorm(.95)*sd(nexpdat$meannonagree[which(nexpdat$majexp6==1)],na.rm=T)/sqrt(length(nexpdat$meannonagree[which(nexpdat$majexp6==1)]))
confagree4<-c(meanagree4-erroragree4,meanagree4+erroragree4)

library(gplots)

plotmatrix1<-matrix(c(meanthought1,meanthought2,meanimp1,meanimp2,meanagree1,meanagree2),nrow=2,ncol=3,byrow=F)
cilmatrix1<-matrix(c(confthought1[1],confthought2[1],confimp1[1],confimp2[1],confagree1[1],confagree2[1]),nrow=2,ncol=3,byrow=F)
ciumatrix1<-matrix(c(confthought1[2],confthought2[2],confimp1[2],confimp2[2],confagree1[2],confagree2[2]),nrow=2,ncol=3,byrow=F)

barplot2(plotmatrix1,beside=T,plot.ci=T,ci.l=cilmatrix1,ci.u=ciumatrix1,main="Reactions to Expert Arguments",ylab = "Less --------------------- More",names.arg=c("Thought About","Consider Important","Agree with"),ylim=c(0,3),col=c(gray(.25),gray(.75)))
legend(x=1,y=3,legend=c("Expert in Minority (N=10)","Expert in Majority (N=46)"),fill=c(gray(.25),gray(.75)))

plotmatrix2<-matrix(c(meanthought3,meanthought4,meanimp3,meanimp4,meanagree3,meanagree4),nrow=2,ncol=3,byrow=F)
cilmatrix2<-matrix(c(confthought3[1],confthought4[1],confimp3[1],confimp4[1],confagree3[1],confagree4[1]),nrow=2,ncol=3,byrow=F)
ciumatrix2<-matrix(c(confthought3[2],confthought4[2],confimp3[2],confimp4[2],confagree3[2],confagree4[2]),nrow=2,ncol=3,byrow=F)

barplot2(plotmatrix2,beside=T,plot.ci=T,ci.l=cilmatrix2,ci.u=ciumatrix2,main="Reactions to Arguments Known by All",ylab = "Less --------------------- More",names.arg=c("Thought About","Consider Important","Agree with"),ylim=c(0,3),col=c(gray(.25),gray(.75)))
legend(x=1,y=3,legend=c("Expert in Minority (N=10)","Expert in Majority (N=46)"),fill=c(gray(.25),gray(.75)))


t.test(nexpdat$meanexpthought[which(nexpdat$majexp6==0)], nexpdat$meanexpthought[which(nexpdat$majexp6==1)],na.rm=T)
t.test(nexpdat$meanexpimp[which(nexpdat$majexp6==0)], nexpdat$meanexpimp[which(nexpdat$majexp6==1)],na.rm=T)
t.test(nexpdat$meanexpagree[which(nexpdat$majexp6==0)], nexpdat$meanexpagree[which(nexpdat$majexp6==1)],na.rm=T)




##Generate Figures 6 and 7 in Appendix, re-analysis using a 3-4 cutpoint

meanthought1<-4-mean(nexpdat$meanexpthought[which(nexpdat$majexp4==0)],na.rm=T)
errorthought1<-qnorm(.95)*sd(nexpdat$meanexpthought[which(nexpdat$majexp4==0)],na.rm=T)/sqrt(length(nexpdat$meanexpthought[which(nexpdat$majexp4==0)]))
confthought1<-c(meanthought1-errorthought1,meanthought1+errorthought1)

meanthought2<-4-mean(nexpdat$meanexpthought[which(nexpdat$majexp4==1)],na.rm=T)
errorthought2<-qnorm(.95)*sd(nexpdat$meanexpthought[which(nexpdat$majexp4==1)],na.rm=T)/sqrt(length(nexpdat$meanexpthought[which(nexpdat$majexp4==1)]))
confthought2<-c(meanthought2-errorthought2,meanthought2+errorthought2)

meanimp1<-4-mean(nexpdat$meanexpimp[which(nexpdat$majexp4==0)],na.rm=T)
errorimp1<-qnorm(.95)*sd(nexpdat$meanexpimp[which(nexpdat$majexp4==0)],na.rm=T)/sqrt(length(nexpdat$meanexpimp[which(nexpdat$majexp4==0)]))
confimp1<-c(meanimp1-errorimp1,meanimp1+errorimp1)

meanimp2<-4-mean(nexpdat$meanexpimp[which(nexpdat$majexp4==1)],na.rm=T)
errorimp2<-qnorm(.95)*sd(nexpdat$meanexpimp[which(nexpdat$majexp4==1)],na.rm=T)/sqrt(length(nexpdat$meanexpimp[which(nexpdat$majexp4==1)]))
confimp2<-c(meanimp2-errorimp2,meanimp2+errorimp2)

meanagree1<-5-mean(nexpdat$meanexpagree[which(nexpdat$majexp4==0)],na.rm=T)
erroragree1<-qnorm(.95)*sd(nexpdat$meanexpagree[which(nexpdat$majexp4==0)],na.rm=T)/sqrt(length(nexpdat$meanexpagree[which(nexpdat$majexp4==0)]))
confagree1<-c(meanagree1-erroragree1,meanagree1+erroragree1)

meanagree2<-5-mean(nexpdat$meanexpagree[which(nexpdat$majexp4==1)],na.rm=T)
erroragree2<-qnorm(.95)*sd(nexpdat$meanexpagree[which(nexpdat$majexp4==1)],na.rm=T)/sqrt(length(nexpdat$meanexpagree[which(nexpdat$majexp4==1)]))
confagree2<-c(meanagree2-erroragree2,meanagree2+erroragree2)

#Generates means and confidence intervals for reactions to non-expert information

meanthought3<-4-mean(nexpdat$meannonthought[which(nexpdat$majexp4==0)],na.rm=T)
errorthought3<-qnorm(.95)*sd(nexpdat$meannonthought[which(nexpdat$majexp4==0)],na.rm=T)/sqrt(length(nexpdat$meannonthought[which(nexpdat$majexp4==0)]))
confthought3<-c(meanthought3-errorthought3,meanthought3+errorthought3)

meanthought4<-4-mean(nexpdat$meannonthought[which(nexpdat$majexp4==1)],na.rm=T)
errorthought4<-qnorm(.95)*sd(nexpdat$meannonthought[which(nexpdat$majexp4==1)],na.rm=T)/sqrt(length(nexpdat$meannonthought[which(nexpdat$majexp4==1)]))
confthought4<-c(meanthought4-errorthought4,meanthought4+errorthought4)

meanimp3<-4-mean(nexpdat$meannonimp[which(nexpdat$majexp4==0)],na.rm=T)
errorimp3<-qnorm(.95)*sd(nexpdat$meannonimp[which(nexpdat$majexp4==0)],na.rm=T)/sqrt(length(nexpdat$meannonimp[which(nexpdat$majexp4==0)]))
confimp3<-c(meanimp3-errorimp3,meanimp3+errorimp3)

meanimp4<-4-mean(nexpdat$meannonimp[which(nexpdat$majexp4==1)],na.rm=T)
errorimp4<-qnorm(.95)*sd(nexpdat$meannonimp[which(nexpdat$majexp4==1)],na.rm=T)/sqrt(length(nexpdat$meannonimp[which(nexpdat$majexp4==1)]))
confimp4<-c(meanimp4-errorimp4,meanimp4+errorimp4)

meanagree3<-5-mean(nexpdat$meannonagree[which(nexpdat$majexp4==0)],na.rm=T)
erroragree3<-qnorm(.95)*sd(nexpdat$meannonagree[which(nexpdat$majexp4==0)],na.rm=T)/sqrt(length(nexpdat$meannonagree[which(nexpdat$majexp4==0)]))
confagree3<-c(meanagree3-erroragree3,meanagree3+erroragree3)

meanagree4<-5-mean(nexpdat$meannonagree[which(nexpdat$majexp4==1)],na.rm=T)
erroragree4<-qnorm(.95)*sd(nexpdat$meannonagree[which(nexpdat$majexp4==1)],na.rm=T)/sqrt(length(nexpdat$meannonagree[which(nexpdat$majexp4==1)]))
confagree4<-c(meanagree4-erroragree4,meanagree4+erroragree4)

library(gplots)

plotmatrix1<-matrix(c(meanthought1,meanthought2,meanimp1,meanimp2,meanagree1,meanagree2),nrow=2,ncol=3,byrow=F)
cilmatrix1<-matrix(c(confthought1[1],confthought2[1],confimp1[1],confimp2[1],confagree1[1],confagree2[1]),nrow=2,ncol=3,byrow=F)
ciumatrix1<-matrix(c(confthought1[2],confthought2[2],confimp1[2],confimp2[2],confagree1[2],confagree2[2]),nrow=2,ncol=3,byrow=F)

barplot2(plotmatrix1,beside=T,plot.ci=T,ci.l=cilmatrix1,ci.u=ciumatrix1,main="Reactions to Expert Arguments",ylab = "Less --------------------- More",names.arg=c("Thought About","Consider Important","Agree with"),ylim=c(0,3),col=c(gray(.25),gray(.75)))
legend(x=1,y=3,legend=c("Expert in Minority (N=16)","Expert in Majority (N=40)"),fill=c(gray(.25),gray(.75)))

plotmatrix2<-matrix(c(meanthought3,meanthought4,meanimp3,meanimp4,meanagree3,meanagree4),nrow=2,ncol=3,byrow=F)
cilmatrix2<-matrix(c(confthought3[1],confthought4[1],confimp3[1],confimp4[1],confagree3[1],confagree4[1]),nrow=2,ncol=3,byrow=F)
ciumatrix2<-matrix(c(confthought3[2],confthought4[2],confimp3[2],confimp4[2],confagree3[2],confagree4[2]),nrow=2,ncol=3,byrow=F)

barplot2(plotmatrix2,beside=T,plot.ci=T,ci.l=cilmatrix2,ci.u=ciumatrix2,main="Reactions to Arguments Known by All",ylab = "Less --------------------- More",names.arg=c("Thought About","Consider Important","Agree with"),ylim=c(0,3),col=c(gray(.25),gray(.75)))
legend(x=1,y=3,legend=c("Expert in Minority (N=16)","Expert in Majority (N=40)"),fill=c(gray(.25),gray(.75)))


t.test(nexpdat$meanexpthought[which(nexpdat$majexp4==0)], nexpdat$meanexpthought[which(nexpdat$majexp4==1)],na.rm=T)
t.test(nexpdat$meanexpimp[which(nexpdat$majexp4==0)], nexpdat$meanexpimp[which(nexpdat$majexp4==1)],na.rm=T)
t.test(nexpdat$meanexpagree[which(nexpdat$majexp4==0)], nexpdat$meanexpagree[which(nexpdat$majexp4==1)],na.rm=T)



##Now using dynamic cutpoint to generate Figures 8&9

#generate means and conf intervals for reactions to expert info


meanthought1<-4-mean(nexpdat$meanexpthought[which(nexpdat$majexpg==0)],na.rm=T)
errorthought1<-qnorm(.95)*sd(nexpdat$meanexpthought[which(nexpdat$majexpg==0)],na.rm=T)/sqrt(length(nexpdat$meanexpthought[which(nexpdat$majexpg==0)]))
confthought1<-c(meanthought1-errorthought1,meanthought1+errorthought1)

meanthought2<-4-mean(nexpdat$meanexpthought[which(nexpdat$majexpg==1)],na.rm=T)
errorthought2<-qnorm(.95)*sd(nexpdat$meanexpthought[which(nexpdat$majexpg==1)],na.rm=T)/sqrt(length(nexpdat$meanexpthought[which(nexpdat$majexpg==1)]))
confthought2<-c(meanthought2-errorthought2,meanthought2+errorthought2)

meanimp1<-4-mean(nexpdat$meanexpimp[which(nexpdat$majexpg==0)],na.rm=T)
errorimp1<-qnorm(.95)*sd(nexpdat$meanexpimp[which(nexpdat$majexpg==0)],na.rm=T)/sqrt(length(nexpdat$meanexpimp[which(nexpdat$majexpg==0)]))
confimp1<-c(meanimp1-errorimp1,meanimp1+errorimp1)

meanimp2<-4-mean(nexpdat$meanexpimp[which(nexpdat$majexpg==1)],na.rm=T)
errorimp2<-qnorm(.95)*sd(nexpdat$meanexpimp[which(nexpdat$majexpg==1)],na.rm=T)/sqrt(length(nexpdat$meanexpimp[which(nexpdat$majexpg==1)]))
confimp2<-c(meanimp2-errorimp2,meanimp2+errorimp2)

meanagree1<-5-mean(nexpdat$meanexpagree[which(nexpdat$majexpg==0)],na.rm=T)
erroragree1<-qnorm(.95)*sd(nexpdat$meanexpagree[which(nexpdat$majexpg==0)],na.rm=T)/sqrt(length(nexpdat$meanexpagree[which(nexpdat$majexpg==0)]))
confagree1<-c(meanagree1-erroragree1,meanagree1+erroragree1)

meanagree2<-5-mean(nexpdat$meanexpagree[which(nexpdat$majexpg==1)],na.rm=T)
erroragree2<-qnorm(.95)*sd(nexpdat$meanexpagree[which(nexpdat$majexpg==1)],na.rm=T)/sqrt(length(nexpdat$meanexpagree[which(nexpdat$majexpg==1)]))
confagree2<-c(meanagree2-erroragree2,meanagree2+erroragree2)

#Generates means and confidence intervals for reactions to non-expert information

meanthought3<-4-mean(nexpdat$meannonthought[which(nexpdat$majexpg==0)],na.rm=T)
errorthought3<-qnorm(.95)*sd(nexpdat$meannonthought[which(nexpdat$majexpg==0)],na.rm=T)/sqrt(length(nexpdat$meannonthought[which(nexpdat$majexpg==0)]))
confthought3<-c(meanthought3-errorthought3,meanthought3+errorthought3)

meanthought4<-4-mean(nexpdat$meannonthought[which(nexpdat$majexpg==1)],na.rm=T)
errorthought4<-qnorm(.95)*sd(nexpdat$meannonthought[which(nexpdat$majexpg==1)],na.rm=T)/sqrt(length(nexpdat$meannonthought[which(nexpdat$majexpg==1)]))
confthought4<-c(meanthought4-errorthought4,meanthought4+errorthought4)

meanimp3<-4-mean(nexpdat$meannonimp[which(nexpdat$majexpg==0)],na.rm=T)
errorimp3<-qnorm(.95)*sd(nexpdat$meannonimp[which(nexpdat$majexpg==0)],na.rm=T)/sqrt(length(nexpdat$meannonimp[which(nexpdat$majexpg==0)]))
confimp3<-c(meanimp3-errorimp3,meanimp3+errorimp3)

meanimp4<-4-mean(nexpdat$meannonimp[which(nexpdat$majexpg==1)],na.rm=T)
errorimp4<-qnorm(.95)*sd(nexpdat$meannonimp[which(nexpdat$majexpg==1)],na.rm=T)/sqrt(length(nexpdat$meannonimp[which(nexpdat$majexpg==1)]))
confimp4<-c(meanimp4-errorimp4,meanimp4+errorimp4)

meanagree3<-5-mean(nexpdat$meannonagree[which(nexpdat$majexpg==0)],na.rm=T)
erroragree3<-qnorm(.95)*sd(nexpdat$meannonagree[which(nexpdat$majexpg==0)],na.rm=T)/sqrt(length(nexpdat$meannonagree[which(nexpdat$majexpg==0)]))
confagree3<-c(meanagree3-erroragree3,meanagree3+erroragree3)

meanagree4<-5-mean(nexpdat$meannonagree[which(nexpdat$majexpg==1)],na.rm=T)
erroragree4<-qnorm(.95)*sd(nexpdat$meannonagree[which(nexpdat$majexpg==1)],na.rm=T)/sqrt(length(nexpdat$meannonagree[which(nexpdat$majexpg==1)]))
confagree4<-c(meanagree4-erroragree4,meanagree4+erroragree4)

library(gplots)

plotmatrix1<-matrix(c(meanthought1,meanthought2,meanimp1,meanimp2,meanagree1,meanagree2),nrow=2,ncol=3,byrow=F)
cilmatrix1<-matrix(c(confthought1[1],confthought2[1],confimp1[1],confimp2[1],confagree1[1],confagree2[1]),nrow=2,ncol=3,byrow=F)
ciumatrix1<-matrix(c(confthought1[2],confthought2[2],confimp1[2],confimp2[2],confagree1[2],confagree2[2]),nrow=2,ncol=3,byrow=F)

barplot2(plotmatrix1,beside=T,plot.ci=T,ci.l=cilmatrix1,ci.u=ciumatrix1,main="Reactions to Expert Arguments",ylab = "Less --------------------- More",names.arg=c("Thought About","Consider Important","Agree with"),ylim=c(0,3),col=c(gray(.25),gray(.75)))
legend(x=1,y=3,legend=c("Expert in Minority (N=18)","Expert in Majority (N=38)"),fill=c(gray(.25),gray(.75)))

plotmatrix2<-matrix(c(meanthought3,meanthought4,meanimp3,meanimp4,meanagree3,meanagree4),nrow=2,ncol=3,byrow=F)
cilmatrix2<-matrix(c(confthought3[1],confthought4[1],confimp3[1],confimp4[1],confagree3[1],confagree4[1]),nrow=2,ncol=3,byrow=F)
ciumatrix2<-matrix(c(confthought3[2],confthought4[2],confimp3[2],confimp4[2],confagree3[2],confagree4[2]),nrow=2,ncol=3,byrow=F)

barplot2(plotmatrix2,beside=T,plot.ci=T,ci.l=cilmatrix2,ci.u=ciumatrix2,main="Reactions to Arguments Known by All",ylab = "Less --------------------- More",names.arg=c("Thought About","Consider Important","Agree with"),ylim=c(0,3),col=c(gray(.25),gray(.75)))
legend(x=1,y=3,legend=c("Expert in Minority (N=18)","Expert in Majority (N=38)"),fill=c(gray(.25),gray(.75)))





#Finally, dropping non-extreme experts to create figures 10 and 11

nexpdat<-nexpdat[which(nexpdat$expext==1),]

#generate means and conf intervals for reactions to expert info

meanthought1<-4-mean(nexpdat$meanexpthought[which(nexpdat$majexp==0)],na.rm=T)
errorthought1<-qnorm(.95)*sd(nexpdat$meanexpthought[which(nexpdat$majexp==0)],na.rm=T)/sqrt(length(nexpdat$meanexpthought[which(nexpdat$majexp==0)]))
confthought1<-c(meanthought1-errorthought1,meanthought1+errorthought1)

meanthought2<-4-mean(nexpdat$meanexpthought[which(nexpdat$majexp==1)],na.rm=T)
errorthought2<-qnorm(.95)*sd(nexpdat$meanexpthought[which(nexpdat$majexp==1)],na.rm=T)/sqrt(length(nexpdat$meanexpthought[which(nexpdat$majexp==1)]))
confthought2<-c(meanthought2-errorthought2,meanthought2+errorthought2)

meanimp1<-4-mean(nexpdat$meanexpimp[which(nexpdat$majexp==0)],na.rm=T)
errorimp1<-qnorm(.95)*sd(nexpdat$meanexpimp[which(nexpdat$majexp==0)],na.rm=T)/sqrt(length(nexpdat$meanexpimp[which(nexpdat$majexp==0)]))
confimp1<-c(meanimp1-errorimp1,meanimp1+errorimp1)

meanimp2<-4-mean(nexpdat$meanexpimp[which(nexpdat$majexp==1)],na.rm=T)
errorimp2<-qnorm(.95)*sd(nexpdat$meanexpimp[which(nexpdat$majexp==1)],na.rm=T)/sqrt(length(nexpdat$meanexpimp[which(nexpdat$majexp==1)]))
confimp2<-c(meanimp2-errorimp2,meanimp2+errorimp2)

meanagree1<-5-mean(nexpdat$meanexpagree[which(nexpdat$majexp==0)],na.rm=T)
erroragree1<-qnorm(.95)*sd(nexpdat$meanexpagree[which(nexpdat$majexp==0)],na.rm=T)/sqrt(length(nexpdat$meanexpagree[which(nexpdat$majexp==0)]))
confagree1<-c(meanagree1-erroragree1,meanagree1+erroragree1)

meanagree2<-5-mean(nexpdat$meanexpagree[which(nexpdat$majexp==1)],na.rm=T)
erroragree2<-qnorm(.95)*sd(nexpdat$meanexpagree[which(nexpdat$majexp==1)],na.rm=T)/sqrt(length(nexpdat$meanexpagree[which(nexpdat$majexp==1)]))
confagree2<-c(meanagree2-erroragree2,meanagree2+erroragree2)

#Generates means and confidence intervals for reactions to non-expert information

meanthought3<-4-mean(nexpdat$meannonthought[which(nexpdat$majexp==0)],na.rm=T)
errorthought3<-qnorm(.95)*sd(nexpdat$meannonthought[which(nexpdat$majexp==0)],na.rm=T)/sqrt(length(nexpdat$meannonthought[which(nexpdat$majexp==0)]))
confthought3<-c(meanthought3-errorthought3,meanthought3+errorthought3)

meanthought4<-4-mean(nexpdat$meannonthought[which(nexpdat$majexp==1)],na.rm=T)
errorthought4<-qnorm(.95)*sd(nexpdat$meannonthought[which(nexpdat$majexp==1)],na.rm=T)/sqrt(length(nexpdat$meannonthought[which(nexpdat$majexp==1)]))
confthought4<-c(meanthought4-errorthought4,meanthought4+errorthought4)

meanimp3<-4-mean(nexpdat$meannonimp[which(nexpdat$majexp==0)],na.rm=T)
errorimp3<-qnorm(.95)*sd(nexpdat$meannonimp[which(nexpdat$majexp==0)],na.rm=T)/sqrt(length(nexpdat$meannonimp[which(nexpdat$majexp==0)]))
confimp3<-c(meanimp3-errorimp3,meanimp3+errorimp3)

meanimp4<-4-mean(nexpdat$meannonimp[which(nexpdat$majexp==1)],na.rm=T)
errorimp4<-qnorm(.95)*sd(nexpdat$meannonimp[which(nexpdat$majexp==1)],na.rm=T)/sqrt(length(nexpdat$meannonimp[which(nexpdat$majexp==1)]))
confimp4<-c(meanimp4-errorimp4,meanimp4+errorimp4)

meanagree3<-5-mean(nexpdat$meannonagree[which(nexpdat$majexp==0)],na.rm=T)
erroragree3<-qnorm(.95)*sd(nexpdat$meannonagree[which(nexpdat$majexp==0)],na.rm=T)/sqrt(length(nexpdat$meannonagree[which(nexpdat$majexp==0)]))
confagree3<-c(meanagree3-erroragree3,meanagree3+erroragree3)

meanagree4<-5-mean(nexpdat$meannonagree[which(nexpdat$majexp==1)],na.rm=T)
erroragree4<-qnorm(.95)*sd(nexpdat$meannonagree[which(nexpdat$majexp==1)],na.rm=T)/sqrt(length(nexpdat$meannonagree[which(nexpdat$majexp==1)]))
confagree4<-c(meanagree4-erroragree4,meanagree4+erroragree4)

library(gplots)

plotmatrix1<-matrix(c(meanthought1,meanthought2,meanimp1,meanimp2,meanagree1,meanagree2),nrow=2,ncol=3,byrow=F)
cilmatrix1<-matrix(c(confthought1[1],confthought2[1],confimp1[1],confimp2[1],confagree1[1],confagree2[1]),nrow=2,ncol=3,byrow=F)
ciumatrix1<-matrix(c(confthought1[2],confthought2[2],confimp1[2],confimp2[2],confagree1[2],confagree2[2]),nrow=2,ncol=3,byrow=F)

barplot2(plotmatrix1,beside=T,plot.ci=T,ci.l=cilmatrix1,ci.u=ciumatrix1,main="Reactions to Expert Arguments",ylab = "Less --------------------- More",names.arg=c("Thought About","Consider Important","Agree with"),ylim=c(0,3),col=c(gray(.25),gray(.75)))
legend(x=1,y=3,legend=c("Expert in Minority (N=8)","Expert in Majority (N=26)"),fill=c(gray(.25),gray(.75)))

plotmatrix2<-matrix(c(meanthought3,meanthought4,meanimp3,meanimp4,meanagree3,meanagree4),nrow=2,ncol=3,byrow=F)
cilmatrix2<-matrix(c(confthought3[1],confthought4[1],confimp3[1],confimp4[1],confagree3[1],confagree4[1]),nrow=2,ncol=3,byrow=F)
ciumatrix2<-matrix(c(confthought3[2],confthought4[2],confimp3[2],confimp4[2],confagree3[2],confagree4[2]),nrow=2,ncol=3,byrow=F)

barplot2(plotmatrix2,beside=T,plot.ci=T,ci.l=cilmatrix2,ci.u=ciumatrix2,main="Reactions to Arguments Known by All",ylab = "Less --------------------- More",names.arg=c("Thought About","Consider Important","Agree with"),ylim=c(0,3),col=c(gray(.25),gray(.75)))
legend(x=1,y=3,legend=c("Expert in Minority (N=8)","Expert in Majority (N=26)"),fill=c(gray(.25),gray(.75)))

